/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thaihung.common;

import java.awt.Color;
import java.sql.SQLException;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author bj
 */
public class Clock extends Thread{
    JLabel lblTime;
    JTextField txtMaDe;
    GetTimer getT = new GetTimer();
    //Font  font = new Font("Tahoma",Font.PLAIN,14);
    public int i=0;
    public int j=0;
    public Clock(JLabel lblTime,JTextField txtMaDe) throws SQLException{
        this.lblTime = lblTime;
        this.txtMaDe = txtMaDe;
        //Lay thoi gian thi      
        i = getT.GetTime(txtMaDe.getText()); 
    }
    
    @Override
    @SuppressWarnings("SleepWhileInLoop")
    public void run()
    {
        while(i>0)
        {
            i--;
            int minute = i/60;
            int Second = i -minute*60;
            String time  =  minute+":"+Second;
            if(minute<10)
            {
                if(Second<10)
                    time ="0" + minute + ":0" + Second;
                else
                    time ="0" + minute + ":" + Second;
            }
            else
            {
                if(Second<10)
                    time = minute + ":0" + Second;
                else
                    time = minute + ":" + Second;
            }
            // System.out.println(j);
            if(i==60)
                lblTime.setForeground(Color.RED);
            lblTime.setText(time);
            try
            {
                j++;
                Thread.sleep(1000);
            }
            catch (InterruptedException ex) {
                System.out.print(ex.toString());
            }
        }
    }
    
//    public void reset() throws SQLException
//    {
//        i = getT.GetTime(txtMaDe.getText()); 
//        j = 0;
//    }
    
//    public static String TimePlay(){
//        int minute = j/60;
//        int Second = j -minute*60;
//        String time  =  minute+":"+Second;
//        if(Second<10){
//        time =minute+":0"+Second;
//        }
//        return time;
//    }
}
